const Router = require('koa-router')
const insertgoods = new Router()
//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
  database: 'running',
  user: 'run',
  port: 5432,
  host: '82.157.94.115',
  password: 'z12345678',
  max: 2
})
function makeId() {
    let id = Math.random().toString(16).substring(2);
    let id2 = Math.random().toString(16).substring(2);
    return (id + id2).substring(0, 12);
}

insertgoods.post('/insertgoods', async ctx => {
  // ctx.body = '首页文章推荐'
  let {goods_name,goods_title,goods_price,goods_img} = ctx.request.body;
  let insertContentPostgresql = `insert into goods (goods_id,goods_name,goods_title,goods_price,goods_img) values ($1, '${goods_name}', '${goods_title}','${goods_price}','http://82.157.94.115:2009/static/images/1.jpg')`;
  let goods = await psql.query(insertContentPostgresql, [makeId()]);
    ctx.body = {
        goods
    };
})

module.exports = insertgoods